/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Mobilottery.Constants;

import java.util.Vector;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author WindowsVista
 */
public class DataHelper
{

    /*public static void DrawHeader(Graphics p_g, int p_width, int p_height, String p_headerText)
    {
    Font font = Consts.UIConsts.FONT_BOLD_LARGE;

    p_g.setFont(font);
    int fontHeight = font.getHeight();

    // set header bg
    p_g.setColor(0x000000);
    p_g.fillRect(0, 0, p_width, fontHeight + 2);

    // set header text
    p_g.setColor(0xffffff);
    p_g.drawString(p_headerText, 1, 1, Graphics.TOP | Graphics.LEFT);

    // set app title
    p_g.setColor(180, 95, 7);
    p_g.drawString("L", p_width - 1, 1, Graphics.TOP | Graphics.RIGHT);
    p_g.setColor(255, 141, 62);
    p_g.drawString("M", p_width - 1 - font.stringWidth("L"), 1, Graphics.TOP | Graphics.RIGHT);
    }

    public static void ClearScreen(Graphics p_g, int p_width, int p_height, int p_color)
    {
    p_g.setColor(p_color);
    p_g.fillRect(0, 0, p_width, p_height);
    }
     */
    /**
     *  split strings
     */
    public static String[] Split(String p_separator, String p_string)
    {
        String[] retStr = null;

        // If the argument string is null
        if (p_string == null)
        {
            // In this case the result strings array also should be null
            retStr = null;
        }
        // If the argument separator is null or empty string
        else if (p_separator == null || p_separator.equals("") == true)
        {
            // In this case the result strings array will contain only one
            // string, which is the argument string
            retStr = new String[]
                    {
                        p_string
                    };
        }
        // Otherwise (if both arguments are valid)
        else
        {
            // In this case the argument string should be splitted by the argument separator
            //  for example:
            //      Explode("\n", "first line\nsecond line\nthird line")
            //      should return new String[] {"first line", "second line", "third line"}
            int place = 0;
            Vector vectorStr = new Vector(1);
            String l_string = p_string;
            String row = "";

            // Find first accurance of the argument separator in argument string
            place = l_string.indexOf(p_separator);

            // Repeat the loop while there is an accurance of the separator
            // in the string (after each found accurance the string is shortened)
            while (place != -1)
            {
                // Get the sub-string until the accurance
                row = l_string.substring(0, place);
                // Insert the sub-string to the local vector
                vectorStr.addElement(row);

                // Shorten the string (cut the sub-string until the separator, including it)
                l_string = l_string.substring(place + p_separator.length());

                // Find next accurance of the separator in the string
                place = l_string.indexOf(p_separator);
            }
            // Add the remained string to the vector (after all the cuts in the while
            // above not the entire string is entered to the vector - there is still one
            // more sub-string in the end)
            vectorStr.addElement(l_string);

            // Create the result array that will hold all the sub-strings
            // (the size of the array is the number of sub-strings
            // that were entered to the local vector).
            retStr = new String[vectorStr.size()];

            // Go over all the sub-strings (elements in the local vector)
            for (int i = 0; i < vectorStr.size(); i++)
            {
                // Add each sub-string to the result strings array
                retStr[i] = (String) vectorStr.elementAt(i);
            }
        }

        // Return the result strings array
        return retStr;
    }
}
